package com.zjj.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

public class MyBatisUtils {
    private static SqlSessionFactory sqlMapper = null;
    static {

        try {
            String resources = "mybatis-config.xml";
            Reader reader= Resources.getResourceAsReader(resources);
            sqlMapper = new
                    SqlSessionFactoryBuilder().build(reader,"dev1");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static SqlSession getSession(){
        return sqlMapper.openSession();
    }



}
